﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows.Controls;
using JMT.Data;

namespace JMT.Controls.Commands
{
    public class AddInterfaceCommand : ICommand
    {
        private ContextMenu _contextMenu;
        private MenuItem _menuItem;

        public AddInterfaceCommand(ContextMenu contextMenu, MenuItem menuItem)
        {
            _contextMenu = contextMenu;
            _menuItem = menuItem;
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            IJContainer<JInterface> jContainer = _contextMenu.DataContext as IJContainer<JInterface>;
            if (jContainer != null)
            {
                JInterface jInterface = new JInterface();
                jInterface.Id = Guid.NewGuid();
                jInterface.Name = string.Format("{0}{1}", JConstString.TInterface, jContainer.GetUniqueIndex<JInterface>());
                JData.Current.AddModel<JInterface>(jContainer, jInterface);
            }
        }
    }
}
